/*
 * Created on 02.06.2004
 *
 * Copyright (c) 2004 The GnutellaSim Project
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
package util;

/**
 * @author bennobaumgartner
 *
 * TODO Comment
 */
/**
 * @author daily_walker
 *
 */
public class DefaultValues {
	/**
	 * Edges
	 */
	public static int getRoutingEdgeCapacity() {
		return routingEdgeCapacityGenerator.getNumber();
	}
	
	/**
	 * @return
	 */
	public static int downloadEdgeCapacity() {
		
		return downloadEdgeCapacity.getNumber();
	}

	
	/**
	 * Nodes
	 */
	public static int getNodeBufferSize() {
		return bufferSizeGenerator.getNumber();
	}

	//
	// Default Values for Ping Protocol
	//

	/**
	 * @return
	 */
	public static int minConnections() {
		
		return minConnectionsGenerator.getNumber();
	}

	public void setMinConnectionsGenerator(NumberGenerator g) {
		minConnectionsGenerator = g;
	}
	
	
	/**
	 * @return
	 */
	public static int maxConnections() {
		
		return maxConnectionsGenerator.getNumber();
	}
	
	public void setMaxConnectionsGenerator(NumberGenerator g) {
		maxConnectionsGenerator = g;
	}
	

	/**
	 * @return
	 */
	public static int pingFrequency() {
		
		return pingFrequencyGenerator.getNumber();
	}
	
	public void setPingFrequencyGenerator(NumberGenerator g) {
		
		if(queryFrequencyGenerator!=null ){
			int check=QueryFrequency();
			if(g.getNumber()>=check){
				pingFrequencyGenerator = new GaussianNumberGenerator((check-5),2);
			}else{
				pingFrequencyGenerator = g;
			}
			}else{
				pingFrequencyGenerator = g;
		}
	}

	/**
	 * @return
	 */
	public static int pingTtl() {
		
		return pingTtlGenerator.getNumber();
	}
	
	public void setPingTtlGenerator(NumberGenerator g) {
		
		pingTtlGenerator = g;
	}
	

	//
	//Default Values for QueryReplay Protocol
	//

	/**
	 * @return
	 */
	public static int queryTtl() {
		
		return queryTtlGenerator.getNumber();
	}
	
	/**
	 * @return
	 */
	public static int NumberOfFiles() {
		
		return numberOfFilesGenerator.getNumber();
	}
	
	
	/**
	 * @return
	 */
	public static int QueryFrequency() {

		return queryFrequencyGenerator.getNumber();
	}

	/**
	 * @return
	 */
	public static int maxNumberOfDownloads() {
		
		return maxDownloadsGenerator.getNumber();
	}

	/**
	 * @return
	 */
	public static int maxNumberOfUploads() {
		
		return maxUploadsGenerator.getNumber();
	}


	/**
	 * @param generator
	 */
	public void setBufferSizeGenerator(NumberGenerator generator) {
		bufferSizeGenerator = generator;
	}
	

	/**
	 * @return
	 */
	public static DefaultValues get() {
		if (singleton == null) singleton = new DefaultValues();
		return singleton;
	}

	/**
	 * @param generator
	 */
	public void setMaxUploadsGenerator(NumberGenerator generator) {
		maxUploadsGenerator = generator;
	}
	
	/**
	 * @param generator
	 */
	public void setMaxDownloadsGenerator(NumberGenerator generator) {
		maxDownloadsGenerator = generator;
	}
	
	/**
	 * @param generator
	 */
	public void setQueryTtlGenerator(NumberGenerator generator) {
		queryTtlGenerator = generator;
	}
	
	/**
	 * @param generator
	 */
	public void setQueryFrequency(NumberGenerator generator) {
		
		if(pingFrequencyGenerator!=null){
			int check=pingFrequency();
			
			if(generator.getNumber()<=check){
				queryFrequencyGenerator = new GaussianNumberGenerator((check+5),2);
			}else{
				queryFrequencyGenerator = generator;
			}
		}else{
			queryFrequencyGenerator = generator;
		}
	}
	
	/**
	 * @param generator
	 */
	public void setNumberOfFilesGenerator(NumberGenerator generator) {
		numberOfFilesGenerator = generator;
	}
	
	/**
	 * @param generator
	 */
	public void setRoutingEdgeCapacityGenerator(NumberGenerator generator) {
		routingEdgeCapacityGenerator = generator;
	}
	
	/**
	 * @param generator
	 */
	public void setDownloadEdgeCapacityGenerator(NumberGenerator generator) {
		downloadEdgeCapacity = generator;
	}
	
	/**
	 * @param generator
	 */
	public void setAppearRateGenerator(NumberGenerator generator) {
		appearRateGenerator = generator;
	}
	
	public static int getAppearRate() {
		return appearRateGenerator.getNumber();
	}
	
	public void setDisappearRateGenerator(NumberGenerator generator) {
		disappearRateGenerator = generator;
	}
	
	public static int getDisappearRate() {
		return disappearRateGenerator.getNumber();
	}
	
	/**
	 * @param b which is a boolean
	 */
	public void setActive(boolean b) {
		active = b;
	}
	
	/**
	 * @param take values at GUI node setting panel
	 * @return boolean active(true) node which is assinged by user at GUI
	 */
    public static boolean getActive() {
		return active;
	}
	
	/**
	 * @param b which is a boolean value and contain Multidownload senario or single download senario
	 *  information assing values GUI to DefaultValues.multidownload
	 */
	public void setisMultidownload(boolean b) {
		multidownload = b;
	}
	
	/**
	 * @return boolean Multidownload(true) or Singledownload(false)
	 * 			which is assinged by user at GUI
	 */
	public static boolean isMultidownload() {
		return multidownload;
	}
   
	
/*	*//**
	 * @param b which is an int value,contain Routers Number in the network, 
	 * 		    assing values GUI to DefaultValues.RouterNumber
	 *//*
	public void setRouterNumber(int b) {
		if(b<=0){
			b=1;
		}
		setMaxNodeNumber((b*(255-8))/2);
		RouterNumber = b;
	}
	
	*//**
	 * @return int router number which is assinged by user at GUI
	 *//*
	public static int getRouterNumber() {
		return RouterNumber;
	}
	
	*//**
	 * @param b which is an int array,take from GUI router setting panel, 
	 * 		    assing values GUI to DefaultValues.RoutersLink
	 * 
	 * @value b hold Kbps link capacity
	 *//*
	public void setRoutersLinkCapacityArray(int[] b) {
		RoutersLink = b;
	}
	
	*//**
	 * @return int array Link Bandwidth which is assign between two router
	 *//*
	public static int[] getRoutersLinkCapacityArray() {
		
		// if not assigned router setting then default one router assign
		if(RoutersLink.length==0){
			RoutersLink[0]=1000;//1Mbps=1000Kbps=1000000bps
		}
		return RoutersLink;
	}
	
	public void setMaxNodeNumber(int b){
		NodeNumber=b;
	}
	
	*//**
	 * @return int maximum creatable node number which is assign by a formula( (routernumber*(255-8))/2 )
	 *//*
	public static int getMaxNodeNumber(){
		return NodeNumber;
	}
	
	public static void Kanitla(){
		
		Main.out.println("\n\n**************************************\n\n");
		
		Main.out.println("Multidownload :"+isMultidownload()+" \nMax Node Number "+getMaxNodeNumber()+" Router Number "+getRouterNumber());
		
		Main.out.println("Routers Link's Bandwidth :");
		
		int[] a=getRoutersLinkCapacityArray();
		
		for(int i=0;i<a.length;i++){
			Main.out.println("Router "+i+" Router "+(i+1)+" Capacity :"+a[i]+" Kbps");
		}
		
		Main.out.println("\n\n**************************************\n\n");
		
	}*/
	
	private static boolean active;
	
	private static boolean multidownload;
	
	/*private static int RouterNumber;
	
	private static int[] RoutersLink;
	
	private static int NodeNumber;*/
	
	private static DefaultValues singleton;

	private static NumberGenerator downloadEdgeCapacity;
	private static NumberGenerator routingEdgeCapacityGenerator;
	private static NumberGenerator numberOfFilesGenerator;
	private static NumberGenerator queryFrequencyGenerator;
	private static NumberGenerator queryTtlGenerator;
	private static NumberGenerator maxDownloadsGenerator;
	private static NumberGenerator maxUploadsGenerator;
	private static NumberGenerator bufferSizeGenerator;
	private static NumberGenerator pingTtlGenerator;
	private static NumberGenerator maxConnectionsGenerator;
	private static NumberGenerator minConnectionsGenerator;
	public static NumberGenerator appearRateGenerator = new ConstantNumberGenerator(0);
	public static NumberGenerator disappearRateGenerator = new ConstantNumberGenerator(0);
	private static NumberGenerator pingFrequencyGenerator;
}
